package com.fita.admin.dao;

import com.demo2do.core.persistence.annotation.Dao;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;
import com.fita.entity.agent.AgentCompany;

import java.util.List;

/**
 * @description:
 * @author: 11200
 * @date: 2019/7/14
 */
@Dao("hibernate")
public interface AgentCompanyDao {

    @Query("SELECT company.primaryAgent.id AS primaryAgentId, COUNT(*) AS amount " +
            "FROM Agent WHERE disabled = false AND company.disabled = false AND company.primaryAgent IS NOT NULL GROUP BY company.primaryAgent.id")
    public List calculateSecondaryAgentAmount();

    /**
     * 查询一级代理公司下二级
     *
     * 代理
     * @param primaryAgentCompany
     * @return
     */
    @Query("FROM AgentCompany WHERE disabled = false AND primaryAgent IS NOT NULL AND primaryAgentRate IS NOT NULL AND primaryAgent.company = :primaryAgentCompany")
    List<AgentCompany> listSecondaryAgentCompanyByPrimaryAgentCompany(@Variable("primaryAgentCompany") AgentCompany primaryAgentCompany);

    /**
     * 列出所有一级代理公司
     * @return
     */
    @Query("FROM AgentCompany WHERE disabled = false AND primaryAgent IS NULL ")
    List<AgentCompany> listAllPrimaryAgentCompany();
}
